Commit 6700b7f8b7472061e5d664165850ec4248694106
Parents : 4890884
Author : Mark Qvist <mark@unsigned.io>
Date : 2024-03-27T18:37:13+01:00
Updated view example
Changes
Diff
diff --git a/docs/example_plugins/view.py b/docs/example_plugins/view.py
index dc66ce93..f8e357c5 100644
--- a/docs/example_plugins/view.py
+++ b/docs/example_plugins/view.py
@@ -158,7 +158,7 @@ class CameraSource(ViewSource):
self.camera_ready = False
class StreamSource(ViewSource):
- DEFAULT_IDLE_TIMEOUT = 5
+ DEFAULT_IDLE_TIMEOUT = 10
def __init__(self, url=None):
self.url = url
@@ -180,19 +180,18 @@ class StreamSource(ViewSource):
try:
while max(self.last_update, self.started)+self.idle_timeout > time.time():
ret, frame = self.stream.read()
- self.stream_ready = True
if not ret:
self.stream_ready = False
- break
-
- if not self.frame_queue.empty():
- if self.frame_queue.qsize() > 1:
- try:
- self.frame_queue.get_nowait()
- except queue.Empty:
- pass
-
- self.frame_queue.put(frame)
+ else:
+ self.stream_ready = True
+ if not self.frame_queue.empty():
+ if self.frame_queue.qsize() > 1:
+ try:
+ self.frame_queue.get_nowait()
+ except queue.Empty:
+ pass
+
+ self.frame_queue.put(frame)
RNS.log(str(self)+" idled", RNS.LOG_DEBUG)
@@ -206,7 +205,10 @@ class StreamSource(ViewSource):
self.start_reading()
while not self.stream_ready:
time.sleep(0.2)
-
+ if self.stream == None:
+ self.source_data = None
+ return
+
frame = self.frame_queue.get()
retval, buffer = cv2.imencode(".png", frame)
self.source_data = io.BytesIO(buffer).getvalue()
@@ -320,4 +322,4 @@ register_view_sources()
# Finally, tell Sideband what class in this
# file is the actual plugin class.
-plugin_class = ViewCommandPlugin
\ No newline at end of file
+plugin_class = ViewCommandPlugin
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────